﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace YFINGenerator
{
    public partial class Factory
    {
        public static string VMHeaderGenerator(VMInfo vmInfo)
        {
            var res = @"//
//此代码由YFINGenerator自动生成
//Copyright (c) 段凯强 2013~2014
//" + DateTime.Now + @"
//
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Expression.Interactivity.Core;

namespace YFIN.View.ViewModels
{
    public class "+vmInfo.Name+@" : INotifyPropertyChanged
    {

        #region INotifyPropertyChanged
        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }
        #endregion

        #region 属性
";
            foreach(var att in vmInfo.Attibutes)
            {
                string a = att.Substring(0, att.IndexOf(':'));
                string _a = a.Insert(1, "_" + a[0].ToString().ToLower());
                _a = _a.Remove(0, 1);
                string type = att.Substring(att.IndexOf(':') + 1);
                res += @"        private " + type + " " + _a + @";
        public " +type+" "+a+@"
        {
            get
            {
                return "+_a+@";
            }
            set
            {
                if ("+_a+@" != value)
                {
                    "+_a+@" = value;
                    NotifyPropertyChanged("+"\""+a+"\""+@");
                }
            }
        }

";
            }
            foreach(var c in vmInfo.Commands)
            {
                res += "        public ICommand "+c+"Command { get; private set; }\n";
            }

            res += @"        #endregion

        public " + vmInfo.Name + @"()
        {
";
            foreach (var c in vmInfo.Commands)
            {
                res += "            " + c + "Command = new ActionCommand(" + c + ");\n";
            }
            res += @"            //TODO:其他初始化
        }

";
            foreach (var c in vmInfo.Commands)
            {
                res += @"        public void " + c + @"()
        {
            //TODO:相应的操作的代码
        }

";
            }
            res += @"    }
}";
            return res;
        }
    }
}
